<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>融资报价</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
<div class="searchArea">
    <form id="searchBar">
        <div class="fieldset1 clearFix">
        	<div class="FXBR">
	            <div class="fieldBox">
	                <div class="label">融资机构名称</div>
	                <div class="field">
	                    <input name="fncInsNm" id="fncInsNm" type="text" class="ui-textbox" value="${fncInsNm }" ligerui="width: 160">
	                </div>
	            </div>
	            <div class="fieldBox">
	                <div class="label">还款类别</div>
	                <div class="field">
	                    <select name="rePyTpCd" id="rePyTpCd" ligerui="width: 160">
	                        <option value="" seleted>请选择</option>
	                        <c:forEach items="${rePyTpCdLst}" var="rePyTpCd">
	                        	<option value="${rePyTpCd.key }">${rePyTpCd.value }</option>
	                        </c:forEach>
	                    </select>
	                </div>
	            </div>
	            <div class="fieldBox">
	                <div class="label">融资基数</div>
	                <div class="field">
	                    <select name="fncCrdnlt" id="fncCrdnlt" ligerui="width: 160">
	                        <option value="" seleted>请选择</option>
	                       	<c:forEach items="${fncCrdnltCdLst}" var="fncCrdnlt">
	                        	<option value="${fncCrdnlt.key}">${fncCrdnlt.value }</option>
	                        </c:forEach>
	                    </select>
	                </div>
	            </div>
	            <div class="fieldBox">
	                <div class="label">报价状态</div>
	                <div class="field">
	                    <select name="fncScmStcd" id="fncScmStcd" ligerui="width: 160">
	                       <option value="">请选择</option>
	                       	<c:forEach items="${fncScmStCdLst}" var="fncScmStcd">
	                        	<option value="${fncScmStcd.key}">${fncScmStcd.value }</option>
	                        </c:forEach>
	                    </select>
	                </div>
	            </div>
            </div>
            
        	<div class="FXBR">
	            <div class="fieldBox">
	                <div class="label">融资报价名称</div>
	                <div class="field">
	                    <input name="fncScmNm" id="fncScmNm" type="text" class="ui-textbox" value="" ligerui="width: 160">
						<input type="hidden" id="fncScmId" name="fncScmId" value="${fncScmId}">
	                </div>
	            </div>
	            <div class="fieldBox">
	                <div class="label">授信名称</div>
	                <div class="field">
	                    <input name="crNm" id="crNm" type="text" class="ui-textbox" value="" ligerui="width: 160">
	                </div>
	            </div>
        	</div>
        	
        	<!-- hide data -->
			<div class="fieldBox col_100" style="display:none;">
				<div class="field">
					<input type="text" id="fncInsId" name="fncInsId" value="${fncInsId}">
				</div>
			</div>
            
            <div class="clearFix"></div>
	            <div class="btnsBox formBtns notRight">
	               <span id="searchBtn" class="sq-button-round">查询</span>
	               <span id="clearBtn" class="sq-button-round">清空</span>
	               <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
	               <!-- <span id="addBtn" class="sq-button-round" onclick="add();">新增</span> -->

	            </div>
        	</div>
        </form>
    </div>
</div>
<div id="ligergrid1" class="sq-grid">
</div>

<script type="text/javascript">

	var fncInsId =$("#fncInsId").val();
	if(fncInsId==null||fncInsId==""){
		 $("#fncInsNm").attr({"disabled":false});
	}else{
		$("#fncInsNm").attr({"disabled":true});
	}

	var grid = null;
	$(function () {
		initGrid();
	    initForm();
		initEvent();
	});
	
	
	$("#clearBtn").click(function(event) {
	    $("#resetBtn").click();  //重置 input-text
	    var form = liger.get("searchBar");
	    form.setData({  //重置select等特殊表单
//			{"fncInsNm":"","rePyTpCd":"1","fncCrdnlt":"2","fncScmStcd":"2","fncScmNm":"","crNm":"","fncInsId":""}
	        "fncInsNm": "",
	        "rePyTpCd": "",
	        "fncCrdnlt": "",
	        "fncScmStcd": "",
	        "fncScmNm": "",       
	        "crNm": "",
	        "fncInsId": ""
	    });
	});
	
	function initForm(){
	    grid = liger.get("ligergrid1");
	    grid.setHeight(100);
	    grid.options.isSingleCheck=true;	
		$("#searchBar").ligerForm();
	}
	
	function initEvent(){
	    $("#searchBtn").click(function(event) {
	         var form = new liger.get("searchBar");
	         var data = form.getData();
	         console.log(JSON.stringify(data));
	         for (var name in data){
	            grid.setParm(name,data[name]);
	         };
	        grid.reload();
	    });
	}
//  SELECT BS.FNC_SCM_ID, BS.FNC_SCM_NM, BS.PD_ID, BS.FNC_INS_ID, BS.CR_ID, BS.REPY_TP, BS.SCM_ST, 
//  BS.STDT, BS.EDDT, BS.FNC_TRM, BS.FNC_CRDNLT, BS.CRT_PSN, BS.UPT_PSN, BS.CRT_TM, BS.UPT_TM,
//  BS.RMRK, BS.IS_VALID, BS.IS_DEL, BS.PRYM_MTD, BS.MRGN_PCT, BS.MRGN_CL_CRDNLT, BS.MRGN_USE_MTD, BS.IRT_BS, 
//  BS.BS_FLOTUP_RTO, BS.FNC_INTRT_TOT, BS.IRR, BS.EXST_EXRT_RSK, BS.EXST_INTRT_RSK, 
//  BS.EXRT_RSK_CNTR, BS.INTRT_RSK_CNTR, BS.CMT_EXRT_SWP, BS.CMT_INTRT_SWP, BS.EXRT_SWP_BNK, 
//  BS.INTRT_SWP_BNK, BS.EXRT_SWP_FEERT, BS.INTRT_SWP_FEERT, BS.DCN_RATE,BS.MRGN_WTHR_IN_PAY,BS.WTHR_FST_PAY,BS.IRT_TPCD,
//  INS.FUND_RAS_INS_NM,CR.CR_NM,
//  CH.LGC_SN,CH.CHRG_TPCD, CH.COST_NM, CH.COST_PCT, CH.COST_CRDNLT, CH.COST_AMT/100 AS COST_AMT,CH.COST_IN_TPCD,CH.PRE_PAY_DATE 
//  FROM FNC_SCM_BSC_INFO BS 
	function initGrid(){
		var fncInsId = $('#fncInsId').val();
		$("#ligergrid1").ligerGrid({
	    	url: '<%=path%>/rfbase/scmbaseinfo/initList.do?fncInsId='+fncInsId,
	    	method : 'get',
	        columns: [
	            { display: '报价名称', name: 'FNC_SCM_NM', minWidth: 100 , align:'center', enabledSort:true,
	            	render: function (rowdata, rowindex, value, column) { 
	            		if(StringUtils.isEmpty(value)){
	                		value = "";
	                	}
	            		var h = '';
	            		    h='<a href="javascript:showDetail(';
	                        h+="'"+rowdata.FNC_SCM_ID+"'";
	                        h+=')">'+value+'</a>'
	                        return h;
	            		}},
	            { display: '关联授信', name: 'CR_NM', width: 180, enabledSort:true,
	            		render: function (rowdata, rowindex, value, column) { 
	            			if(StringUtils.isEmpty(value)){
		                		value = "";
		                	}
		            		var h = '';
		            		    h='<a href="javascript:showCrBscInfoDetail(';
		                        h+="'"+rowdata.CR_INFO_ID+"'";
		                        h+=')">'+value+'</a>'
		                        return h;
		            		}},
	            { display: '报价状态', name: 'SCM_ST_DES', width: 120 , enabledSort:true},
	            { display: '添加人', name: 'CRT_PSN', width: 1,align:'left', enabledSort:true, hide:true},
	            { display: '起始日期', name: 'STDT', width: 180 , render:renderDate, enabledSort:true},
	            { display: '结束日期', name: 'EDDT', width: 180 , render:renderDate, enabledSort:true},
	            { display: '融资期限', name: 'FNC_TRM', width: 80, enabledSort:true},
	            { display: '还款类别', name: 'REPY_TP_DES', width: 120, align:'center', enabledSort:true},
/* 	            { display: '流程编号', width: 180,
	            	render: function (rowdata, rowindex, value){
	            		var h= "";
	            		if(StringUtils.isNotEmpty(rowdata.pno)){
		            		h='<a href="javascript:showFlow(';
		            		h+="'"+rowdata.pinstId+"'";
		            		h+=",'"+rowdata.audStsCd+"'";
		            		h+=",'"+rowdata.fncScmId+"'";
		                    h+=')">'+rowdata.pno+'</a>';
	            		}
	                	return h;
	            	}	
	            }, */
	            getGridOperColumnContent()
	        ],
	        usePager:false,
	        hideLoadButton : true,
	        width: '100%',
	        height:'100%',
	        heightDiff:-2,
	        checkbox:true,
	        rownumbers:true
	    });	
	}
	
	//隐藏掉操作列
    function getGridOperColumnContent(){
    	var data = {
                display: '操作',
                isSort: false,
                width: 280,
                align:'left',
                render: function (rowdata, rowindex, value){
                    var g="";
                    if(rowdata.SCM_ST == 1){
            			g+='<a class="sq-button-hasicon" href="javascript:startFlow(';
		                g+="'"+rowdata.FNC_SCM_ID+"'";
		                g+=')"><i class="sqBtnIco_4"></i>发起审核流程</a>';
                    }
                    var h="";
                    var i="";
                    if(rowdata.SCM_ST == 1){
                    	h+='<a class="sq-button-hasicon" alt="修改" href="javascript:modifyRow(';
                        h+="'"+rowdata.FNC_SCM_ID+"'";
                        h+=",'"+rowdata.SCM_ST+"'";
                        h+=",'ligergrid_bankacc'";
                        h+=")\"><i class=\"sqBtnIco_4\"></i>"+LogUtils.LOG_CMM_GRID_BTN_MODIFY+"</a>";
                        
            			i+='<a class="sq-button-hasicon" href="javascript:cancelData(';
		                i+="'"+rowdata.FNC_SCM_ID+"'";
		                i+=')"><i class="sqBtnIco_4"></i>作废</a>';
                    }
                    return g+h+i;
                }
        	 }
        	return data;
	}
	//格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
		}
		return dateStr;
	}
	//新增
	function add(){
		var callback = function(){
			 grid.reload();
		}
		var timestamp=new Date().getTime();
		Add_navTab( 'tab_scm_bsc_info_add'+timestamp,'添加融资报价','<%=path%>/rfbase/scmbaseinfo/toAddPage.do?fncInsId=170519203000184&fncInsNm=test',callback);
	}
	
  	function modifyRow(_id){
		var callback = function(){
			 grid.reload();
		}
		var timestamp=new Date().getTime();
		Add_navTab( 'tab_scm_bsc_info_mod'+timestamp,'修改融资报价','<%=path%>/rfbase/scmbaseinfo/toModifyPage.do?fncScmId='+_id,callback);
  	}
  	
  	function showDetail(id){
		var callback = function(){
			 grid.reload();
		}
		var timestamp=new Date().getTime();
		Add_navTab( 'tab_scm_bsc_info_detl'+timestamp,'查看融资报价','<%=path%>/rfbase/scmbaseinfo/toDetail.do?id='+id,callback);
  	}
  	
  	function cancelData(id){
        $.ligerDialog.confirm('您正在作废本报价！请确认！', function (yes)
                {
                    if(yes){
                		$.ajax({
                    		type: 'post',
                    		dataType:'json',
                    		data:{
                    			id:id
                    		},
                    		url: '<%=path%>/rfbase/scmbaseinfo/cancelData.do',
                    		success:function(msg){
                    			 if(msg.success == 1){
                  					 UIUtils.alertSuccessHold1(msg.info);
                   				 	 grid.reload();
                       			 }else{
                      				UIUtils.alertErrorHold1(msg.info);
                       			 }
                    		}
                    	}); 
                    }                    
                }); 		
  	}
	//发起审核流程
	function startFlow(_id){
		if(!_id)return;
		var modelTyp = 'R002';
        var flowDialog = $.ligerDialog.SQopen({
            url: '<%=path%>/flow/flow/toForStartListPage.do?modelTyp='+modelTyp,
            width: 700,
            height:400,
            title : '请选择要发起的流程',
            buttons: [{
	                text: "确定", type: 'ok', cls: 'l-dialog-btn-ok',
	                onclick: function (item, Dialog) {
	                    if (Dialog.onOk) Dialog.onOk();
	                }
	            }, {
	                text: "取消", type: 'cancel', cls: 'l-dialog-btn-no',
	                onclick: function (item, Dialog) {
	                    if (Dialog.onCancel) Dialog.onCancel();
	                }
	            }
	        ],
            onClose: function () {
            	var json = flowDialog._DATA;
            	console.log(json);
            	if(!json){
                	return;
            	}
            	var wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting",onClose: function () {}});
        		$.ajax({
            		type: 'post',
            		dataType:'json',
            		data:{
            			id:_id,
            			procDefKey:json.procDefKey,
            			procDefId:json.procDefId,
            			procNo:json.procNo
            		},
            		url: '<%=path%>/rfbase/scmbaseinfo/addFlowStart.do',
            		success:function(msg){
            			wait_dialog.close();
            			 if(msg.success == 1){
          					 UIUtils.alertSuccessHold1(msg.info);
           				 	 grid.reload();
	           			 }else{
	          				UIUtils.alertErrorHold1(msg.info);
	           			 }
            		}
            	});
            }
        });
	}
	//显示流程
    function showFlow(_pInstId,_audStsCd,_businessKey){
    	if(StringUtils.isEmpty(_pInstId)){
    		UIUtils.alertWarning(CommonConstant.C_P_INSTANCEID_NOT_HERE);
    		return;
    	}
    	var _formUrl = "/rfbase/scmbaseinfo/toDetail.do?isFlow=1@@id=";
    	var params = "?pInsId="+_pInstId+"&status="+_audStsCd+"&businessKey="+_businessKey+"&formUrl="+_formUrl;
    	Add_navTab('tab_spl_bank_flow_'+_pInstId,'查看流程',"<%=path%>/flow/flow/toFlowShowPageFowBus.do"+params);
    }
	
    //授信详情
	function showCrBscInfoDetail(id){
		if(!id)return;
		var lgcId=id;
		var timestamp=new Date().getTime();
		Add_navTab('PrdSpl_3'+timestamp,'授信详情','<%=path%>/rfbase/crbaseinfo/toDetailPage.do?lgcId='+lgcId);
	}
	
</script>
</body>
</html>